﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Drawing;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Data;
/// <summary>
/// Summary description for GGPremiumListPDFOutput
/// </summary>
public class GGPremiumListPDFOutput
{
    private string _carid;
    private DataTable _dtresult;
    private string _title;
    private string _footer;

    private string _carplatenumber;
    private string _customername;
    private string _mobile;
    private string _email;
    private string _gender;
    

    private string _dob;
  
    private string _occupation;//
   

    private string _currentinsurer;
    private string _carmakemodel;
    private string _carmodelyear;
 
    private string _ncb;
    private string _anyclaim;
  
    private string _nameddriver;
    private string _commencementdate;
    private string _quotedate;

    private string _insuranceType;
    private string _includeCTPL;
    private string _sumInsuredAmount;
    private string _vehicleTypeUsage;
    private string _garageType;
    private string _agentName;
    private string _agentContactNo;
    private string _agentEmail;
    private string _agentLicenseNo;
    private string _agentSupervisor;
    private string _agentSupLicenseNo;

    private string _extcomdate = "";

    public string CarId
    {
        get { return _carid; }
        set { _carid = value; }
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }

    public string Footer
    {
        get { return _footer; }
        set { _footer = value; }
    }

    public string CustomerName
    {
        get { return _customername; }
        set { _customername = value; }
    }

    public string CarPlateNumber
    {
        get { return _carplatenumber; }
        set { _carplatenumber = value; }
    }

    public string CurrentInsurer
    {
        get { return _currentinsurer; }
        set { _currentinsurer = value; }
    }

    public string CarMakeModel
    {
        get { return _carmakemodel; }
        set { _carmakemodel = value; }
    }

    public string Email
    {
        get { return _email; }
        set { _email = value; }
    }

    public string Mobile
    {
        get { return _mobile; }
        set { _mobile = value; }
    }

    public string DOB
    {
        get { return _dob; }
        set { _dob = value; }
    }

    public string Gender
    {
        get { return _gender; }
        set { _gender = value; }
    }

    public string NCB
    {
        get { return _ncb; }
        set { _ncb = value; }
    }

    public string CarModelYear
    {
        get { return _carmodelyear; }
        set { _carmodelyear = value; }
    }

    public string NamedDriver
    {
        get { return _nameddriver; }
        set { _nameddriver = value; }
    }

    public string IncludeCTPL
    {
        get { return _includeCTPL; }
        set { _includeCTPL = value; }
    }

    public string SumInsuredAmount
    {
        get { return _sumInsuredAmount; }
        set { _sumInsuredAmount = value; }
    }

    public string VehicleTypeUsage
    {
        get { return _vehicleTypeUsage; }
        set { _vehicleTypeUsage = value; }
    }

    public string GarageType
    {
        get { return _garageType; }
        set { _garageType = value; }
    }

    public string InsuranceType
    {
        get { return _insuranceType; }
        set { _insuranceType = value; }
    }

    public string AgentName
    {
        get { return _agentName; }
        set { _agentName = value; }
    }

    public string Occupation
    {
        get { return _occupation; }
        set { _occupation = value; }
    }

    public string AgentContactNo
    {
        get { return _agentContactNo; }
        set { _agentContactNo = value; }
    }

    public string AgentEmail
    {
        get { return _agentEmail; }
        set { _agentEmail = value; }
    }

    public string AgentLicenseNo
    {
        get { return _agentLicenseNo; }
        set { _agentLicenseNo = value; }
    }

    public string AgentSupervisor
    {
        get { return _agentSupervisor; }
        set { _agentSupervisor = value; }
    }

    public string AgentSupLicenseNo
    {
        get { return _agentSupLicenseNo; }
        set { _agentSupLicenseNo = value; }
    }
    
   

    public string AnyClaim
    {
        get { return _anyclaim; }
        set { _anyclaim = value; }
    }

    public string CommnecementDate
    {
        get { return _commencementdate; }
        set { _commencementdate = value; }
    }

    public string ExtComDate
    {
        get { return _extcomdate; }
        set { _extcomdate = value; }
    }

    public string QuoteDateTime
    {
        get { return _quotedate; }
        set { _quotedate = value; }
    }

    public DataTable ResultGridTable
    {
        get { return _dtresult; }
        set { _dtresult = value; }
    }

    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

	public GGPremiumListPDFOutput()
	{
        _title = "";
        _footer = "";
        _dtresult = null;
	}

    public string GeneratePDF(string lang, bool shPromotion)
    {
        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        // Set font encoding to unicode

        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

        document.Info.Title = "Created with PDFsharp";

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        

        // Create a font
        XFont fontHeader = new XFont("Tahoma", 11, XFontStyle.Bold, options);
        XFont font = new XFont("Tahoma", 7.5d, XFontStyle.Regular, options);
        XFont fontFooter = new XFont("Tahoma", 7, XFontStyle.Bold, options);
        XFont fontAddress = new XFont("Tahoma", 10, XFontStyle.Regular, options);
        XColor _xcolor = new XColor();
        _xcolor.R = 0;
        _xcolor.G = 0;
        _xcolor.B = 0;
        System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(10, 10, 500, 100);
        XPen _pen = new XPen(_xcolor);
      
        int curX = 35;
        int curY = 30;

        
        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address1, fontHeader, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address2, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address3, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address4, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address5, fontAddress, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 10;

        gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "/images/logos/gg_logo.png"), new XRect(curX + 380, 35, 73, 63));
        curY += 10;
        gfx.DrawString(Resources.CarInsurance.PDF_Title, fontHeader, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        //Sakthi on 14 Nov 2012 -- End

        curY += 15;// 20;

        gfx.DrawString(Resources.CarInsuranceResultPage.CustomerName, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_customername, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.DateNew, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 390, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(dateTimeNow.ToString("dd/MMM/yyyy"), font, XBrushes.Black, new XRect(curX + 395, curY, 50, 15), XStringFormat.TopLeft);
        //DateTime.Now.ToString("dd/MMM/yyyy")

        curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.ContactNo, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_mobile, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.LicensePlate, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 390, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carplatenumber, font, XBrushes.Black, new XRect(curX + 395, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.CarMakeModel, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carmakemodel, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.Year, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 390, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carmodelyear, font, XBrushes.Black, new XRect(curX + 395, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsurance.VehicleType, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(VehicleTypeUsage, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        gfx.DrawString(Resources.CarInsurance.NamedDriver, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 390, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_nameddriver, font, XBrushes.Black, new XRect(curX + 395, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsurance.NCB, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_ncb, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        
        gfx.DrawString(Resources.CarInsuranceResultPage.PolicyStartDate, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 390, curY, 50, 15), XStringFormat.TopLeft);
        if (_extcomdate.Trim() == "")
        {
            gfx.DrawString(_commencementdate, font, XBrushes.Black, new XRect(curX + 395, curY, 50, 15), XStringFormat.TopLeft);
        }
        else
        {
            gfx.DrawString(_commencementdate + " " + Resources.CarInsuranceResultPage.PolicyToDate + " " + _extcomdate, font, XBrushes.Black, new XRect(curX + 395, curY, 100, 15), XStringFormat.TopLeft);
        }

       
        curY += 10;
        gfx.DrawString(Resources.CarInsurance.PolicyDetail, fontAddress, XBrushes.Black, new XRect(curX, curY, 100, 15), XStringFormat.TopLeft);
        curY += 10;
        if (_dtresult != null && _dtresult.Rows.Count > 0)
        {
            DataTable _dtResultClean = new DataTable("tblResultClean");

            _dtResultClean.Columns.Add(Resources.General.InsuranceCompany);
            for (int i = 0; i < _dtresult.Rows.Count; i++)
            {
                //Company Name
                _dtResultClean.Columns.Add(_dtresult.Rows[i][6].ToString() + i.ToString());
            }

            DataRow _rowLogo = _dtResultClean.NewRow();
            _rowLogo[0] = Resources.General.InsuranceCompany;
            //_dtResultClean.Rows.Add(_rowLogo);

            DataRow _rowInsType = _dtResultClean.NewRow();
            _rowInsType[0] = Resources.CarInsurance.InsuranceType;

            DataRow _rowQuoteRefNo = _dtResultClean.NewRow();
            _rowQuoteRefNo[0] = Resources.CarInsurance.ReferenceNo;

            
            DataRow _rowGarageType = _dtResultClean.NewRow();
            _rowGarageType[0] = Resources.CarInsurance.GarageType;

            DataRow _rowDeductible = _dtResultClean.NewRow();
            _rowDeductible[0] = Resources.CarInsuranceResultPage.DECNormal;

            DataRow _rowFireTheft = _dtResultClean.NewRow();
            _rowFireTheft[0] = Resources.CarInsuranceResultPage.FireTheftNormal;

            DataRow _rowOwnDamage = _dtResultClean.NewRow();
            _rowOwnDamage[0] = Resources.CarInsuranceResultPage.OwnDamage;

            DataRow _rowTPPD = _dtResultClean.NewRow();
            _rowTPPD[0] = Resources.CarInsuranceResultPage.TPPDNormal;

            DataRow _rowTPBIA = _dtResultClean.NewRow();
            _rowTPBIA[0] = Resources.CarInsuranceResultPage.TPBIANormal;

            DataRow _rowTPBIP = _dtResultClean.NewRow();
            _rowTPBIP[0] = Resources.CarInsuranceResultPage.TPBIPNormal;

            DataRow _rowPA = _dtResultClean.NewRow();
            _rowPA[0] = Resources.CarInsuranceResultPage.PANormal;

            DataRow _rowMED = _dtResultClean.NewRow();
            _rowMED[0] = Resources.CarInsuranceResultPage.MEDNormal;

            DataRow _rowBB = _dtResultClean.NewRow();
            _rowBB[0] = Resources.CarInsuranceResultPage.BailBondNormal;

           
            DataRow _rowTotalVMI = _dtResultClean.NewRow();
            _rowTotalVMI[0] = Resources.CarInsurance.VMI;

            DataRow _rowCTPL = _dtResultClean.NewRow();
            _rowCTPL[0] = Resources.CarInsurance.CMI;
            

            DataRow _rowTotalPremium = _dtResultClean.NewRow();
            _rowTotalPremium[0] = "1). " + Resources.CarInsurance.FullPaymentwithTAX;

            DataRow _rowGGOffer = _dtResultClean.NewRow();
            _rowGGOffer[0] = Resources.General.AnnualPremium;

            DataRow _rowFloodCover = _dtResultClean.NewRow();
            _rowFloodCover[0] = Resources.CarInsuranceResultPage.FloodCover;

            DataRow _rowNameDriver = _dtResultClean.NewRow();
            _rowNameDriver[0] = Resources.NonGG.NamedDrivers;

            DataRow _rowPaymentOption = _dtResultClean.NewRow();
            _rowPaymentOption[0] = Resources.CarInsurance.PaymentOptions;

            DataRow _rowMonthlyInstallmentTitle = _dtResultClean.NewRow();
            _rowMonthlyInstallmentTitle[0] = Resources.CarInsurance.MonthlyInstallments;

            DataRow _rowInstallmentPerMonth = _dtResultClean.NewRow();
            _rowInstallmentPerMonth[0] = "2). " + Resources.CarInsurance.CashPayment; //Resources.CarInsurance.MonthlyInstallment;

            DataRow _rowNoOfInstallment = _dtResultClean.NewRow();
            _rowNoOfInstallment[0] = "3). " + Resources.CarInsurance.MonthlyInstallment; //Resources.CarInsurance.NoofInstallments;

            DataRow _rowCreditCardby = _dtResultClean.NewRow();
            _rowCreditCardby[0] = Resources.CarInsurance.CreditCardby;

            DataRow _rowZeroInterestFree = _dtResultClean.NewRow();
            _rowZeroInterestFree[0] = Resources.CarInsurance.ZeroPercentInterestFree;
    
            DataRow _rowThirdPartyCoverTitle = _dtResultClean.NewRow();
            _rowThirdPartyCoverTitle[0] = Resources.CarInsurance.ThirdPartyCover;

            DataRow _rowOwnerDamageCoverTitle = _dtResultClean.NewRow();
            _rowOwnerDamageCoverTitle[0] = Resources.CarInsurance.OwnerDamageCover;

            DataRow _rowAddCoverageperEndorseTitle = _dtResultClean.NewRow();
            _rowAddCoverageperEndorseTitle[0] = Resources.CarInsurance.AddCoverageperEndorsement;

            

            for (int r = 0; r < _dtresult.Rows.Count; r++)
            {
                string _logoUrl = _dtresult.Rows[r][7].ToString();

                _rowLogo[r + 1] = _logoUrl.Substring(1, _logoUrl.Length - 1); // LOGO
                if (_dtresult.Rows[r][16] != DBNull.Value && _dtresult.Rows[r][16].ToString() != string.Empty)
                {
                    _rowQuoteRefNo[r + 1] = _dtresult.Rows[r][16]; // Ref. No
                }
                else
                {
                    _rowQuoteRefNo[r + 1] = CE.Global.General.GetReferenceNumber(_dtresult.Rows[r][3].ToString(), _dtresult.Rows[r][1].ToString());
                }

                
                if (_dtresult.Rows[r][2] != DBNull.Value && _dtresult.Rows[r][2] != string.Empty)
                {
                    if (_dtresult.Rows[r][2].ToString() == "10")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class10; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "11")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class11; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "20")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class20; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "21")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class21; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "30")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class30; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "31")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class31; // Ins Type
                    }
                }

                
                if (_dtresult.Rows[r][14] != DBNull.Value && _dtresult.Rows[r][14] != string.Empty)
                {
                    if (_dtresult.Rows[r][14].ToString() == "1")
                    {
                        _rowGarageType[r + 1] = Resources.CarInsurance.Garage_Authorized; // Garage Type
                    }
                    else
                    {
                        _rowGarageType[r + 1] = Resources.CarInsurance.Garage_Dealer; // Garage Type
                    }
                }
                


                _rowGGOffer[r + 1] = Convert.ToSingle(_dtresult.Rows[r][17]).ToString("#,000.00"); // AnnualPremium
               

                _rowTotalVMI[r + 1] = Convert.ToSingle(_dtresult.Rows[r][18]).ToString("#,000.00"); //PromotionPrice
               
                if (Convert.ToInt32(_dtresult.Rows[r][21]) > 0)
                {
                    if (Convert.ToInt32(_dtresult.Rows[r][21]) >= 1000)
                    {
                        _rowCTPL[r + 1] = Convert.ToSingle(_dtresult.Rows[r][21]).ToString("#,000.00"); //TotalCMI
                    }
                    else
                    {
                        _rowCTPL[r + 1] = Convert.ToSingle(_dtresult.Rows[r][21]).ToString("#.00"); //TotalCMI
                    }
                }
                else
                {
                    _rowCTPL[r + 1] = "N/A";
                } /**/
            

                _rowTotalPremium[r + 1] = (Convert.ToSingle(_dtresult.Rows[r][21].ToString()) + Convert.ToSingle(_dtresult.Rows[r][18].ToString())).ToString("#,000.00");
               
                _rowThirdPartyCoverTitle[r + 1] = " ";
                _rowOwnerDamageCoverTitle[r + 1] = " ";
                _rowAddCoverageperEndorseTitle[r + 1] = " ";
              
               
                Int64 _strBrokerProvider = 0;
                string _strPaymentOption = "FP";
                string _strFirstInstallment = "0.00";
                string _strLastInstallment = "0.00";
                Int32 _Days = 0;
                Int32 _Installments = 3;
                Int32 _Install = _Installments - 1;
                string _strFirstInstallmentDesc = "";
                string _strLastInstallmentDesc = "";
                string _InerestFree = "√";
                string _BankCode = "BKK";

                if (_dtresult.Rows[r]["CXBrokerProviderId"] != DBNull.Value && _dtresult.Rows[r]["CXBrokerProviderId"].ToString() != string.Empty)
                {
                    _strBrokerProvider = Convert.ToInt32(_dtresult.Rows[r]["CXBrokerProviderId"].ToString());
                }

                if (_dtresult.Rows[r]["DiffDate"] != DBNull.Value && _dtresult.Rows[r]["DiffDate"].ToString() != string.Empty)
                {
                    _Days = Convert.ToInt32(_dtresult.Rows[r]["DiffDate"].ToString());
                }

                if (_dtresult.Rows[r]["PaymentOption"] != DBNull.Value && _dtresult.Rows[r]["PaymentOption"].ToString() != string.Empty)
                {
                    _strPaymentOption = _dtresult.Rows[r]["PaymentOption"].ToString();
                }

                if (_dtresult.Rows[r]["NoofInstallMent"] != DBNull.Value && _dtresult.Rows[r]["NoofInstallMent"].ToString() != string.Empty)
                {
                    _Installments = Convert.ToInt32(_dtresult.Rows[r]["NoofInstallMent"].ToString());
                }

                if (_dtresult.Rows[r]["Bank"] != DBNull.Value && _dtresult.Rows[r]["Bank"].ToString() != string.Empty)
                {
                    _BankCode = _dtresult.Rows[r]["Bank"].ToString();
                }
                _strFirstInstallmentDesc = "(1 " + Resources.CarInsurance.To + " " + _Install.ToString() + " " + Resources.CarInsurance.Months + ")";
                _strLastInstallmentDesc = Resources.CarInsurance.LastMonthInstallment;

                if (_strBrokerProvider == 29)
                {
                    if (_BankCode == "KBANK")
                    {
                        _InerestFree = "√";
                    }
                    else
                    {
                        _InerestFree = "X";
                    }
                    _strFirstInstallment = (Convert.ToSingle(_dtresult.Rows[r]["InstallmentAmountWD"].ToString())).ToString("#,000.00");
                    _strLastInstallment = (Convert.ToSingle(_dtresult.Rows[r]["LastInstallmentAmountWD"].ToString())).ToString("#,000.00");

                }
                else
                {
                    _strFirstInstallment = (Convert.ToSingle(_dtresult.Rows[r]["InstallmentAmountWOD"].ToString())).ToString("#,000.00");
                    _strLastInstallment = (Convert.ToSingle(_dtresult.Rows[r]["LastInstallmentAmountWOD"].ToString())).ToString("#,000.00");
                }

                float AP = 0.0f;
                float CMI = 0.0f;
                float Total = 0.0f;
                if (_Installments > 0)
                {
                    if (!float.TryParse(_dtresult.Rows[r]["AnnualPremium"].ToString(), out AP))
                    {
                        AP = 0.0f;
                    }
                    if (!float.TryParse(_dtresult.Rows[r]["Finfo2"].ToString(), out CMI))
                    {
                        CMI = 0.0f;
                    }
                    Total = AP + CMI;
                    _strFirstInstallment = (Total / _Installments).ToString("#,000.00");
                    _strLastInstallment = (Total / _Installments).ToString("#,000.00");
                }
                else
                {
                    _strFirstInstallment = "-";
                    _strLastInstallment = "-";
                }
                _rowPaymentOption[r + 1] = " ";
                _rowMonthlyInstallmentTitle[r + 1] = " ";
               

                _rowInstallmentPerMonth[r + 1] = Total.ToString("#,000.00");
                _rowNoOfInstallment[r + 1] = Total.ToString("#,000.00") + " (" + 
                        _Installments.ToString() + " x " + _strFirstInstallment + ")";
              
                _rowCreditCardby[r + 1] = GetBankName(_BankCode);
                _rowZeroInterestFree[r + 1] = _InerestFree;

              

                _rowTPPD[r + 1] = Convert.ToSingle(_dtresult.Rows[r][23]).ToString("#,000"); ; //TPPD
              
                _rowTPBIP[r + 1] = Convert.ToSingle(_dtresult.Rows[r][24]).ToString("#,000"); ; //TPBIP
                
                _rowTPBIA[r + 1] = Convert.ToSingle(_dtresult.Rows[r][25]).ToString("#,000"); ; //TPBIA
                _rowDeductible[r + 1] = _dtresult.Rows[r][26]; //DEC
              
                _rowFireTheft[r + 1] = Convert.ToSingle(_dtresult.Rows[r][28]).ToString("#,000"); ; //FireTheft
              
                _rowOwnDamage[r + 1] = Convert.ToSingle(_dtresult.Rows[r][29]).ToString("#,000"); ; //OwnDamage
          
                _rowPA[r + 1] = Convert.ToSingle(_dtresult.Rows[r][30]).ToString("#,000"); ; //PADriver
            
                _rowMED[r + 1] = Convert.ToSingle(_dtresult.Rows[r][32]).ToString("#,000"); ; //MedicalExpense
          
                _rowBB[r + 1] = Convert.ToSingle(_dtresult.Rows[r][33]).ToString("#,000"); ; //BailBond

                if (_dtresult.Rows[r][37] != DBNull.Value)
                {
                    _rowFloodCover[r + 1] = _dtresult.Rows[r][37]; //Flood Cover (Info5)
                }

                if (_dtresult.Rows[r][38] != DBNull.Value) //Named Driver (Info6)
                {
                    if (_dtresult.Rows[r][38].ToString() == "1")
                    {
                        _rowNameDriver[r + 1] = "Yes";
                    }
                    else
                    {
                        _rowNameDriver[r + 1] = "No";
                    }
                }
            }

            _dtResultClean.Rows.Add(_rowLogo);
            _dtResultClean.Rows.Add(_rowInsType);
            _dtResultClean.Rows.Add(_rowQuoteRefNo);
            //_dtResultClean.Rows.Add(_rowPackage);
            _dtResultClean.Rows.Add(_rowGarageType);
            _dtResultClean.Rows.Add(_rowNameDriver);

            _dtResultClean.Rows.Add(_rowThirdPartyCoverTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowTPBIP);     //Bodily Injury/Death (per person) 
            _dtResultClean.Rows.Add(_rowTPBIA);     //Liability for Bodily Injury/Death 
            _dtResultClean.Rows.Add(_rowTPPD);      //Liability for Property Damage
            _dtResultClean.Rows.Add(_rowDeductible);

            _dtResultClean.Rows.Add(_rowOwnerDamageCoverTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowOwnDamage);
            _dtResultClean.Rows.Add(_rowFireTheft);
            _dtResultClean.Rows.Add(_rowFloodCover);

            _dtResultClean.Rows.Add(_rowAddCoverageperEndorseTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowPA);        //Personal Accident (per person)
            _dtResultClean.Rows.Add(_rowMED);       //Medical Expenses (per person)
            _dtResultClean.Rows.Add(_rowBB);        //Bail Bond (per accident)

            //Sakthi Hide on 23 Nov 2012 -- Start
            _dtResultClean.Rows.Add(_rowCTPL);
            _dtResultClean.Rows.Add(_rowTotalVMI);
            //Sakthi Hide on 23 Nov 2012 -- End
            _dtResultClean.Rows.Add(_rowPaymentOption);
            _dtResultClean.Rows.Add(_rowTotalPremium);


           
            _dtResultClean.Rows.Add(_rowInstallmentPerMonth);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowNoOfInstallment);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowCreditCardby);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowZeroInterestFree);//Sakthi add on 03 Dec 2012


            
            int _colCount = _dtResultClean.Columns.Count;
            int _rowCount = _dtResultClean.Rows.Count;

            string[] _arrHeader = new string[_colCount];
            int[] _colWidth = new int[_colCount];
            for (int i = 0; i < _colCount; i++)
            {
                _arrHeader[i] = _dtResultClean.Columns[i].ColumnName;
                if (i == 0)
                {
                    _colWidth[i] = 150;
                }
                else
                {
                    _colWidth[i] = 90;
                }
            }

            string[,] _arrData = new string[_rowCount, _colCount];
            for (int r = 0; r < _rowCount; r++)
            {
                for (int c = 0; c < _colCount; c++)
                {
                    _arrData[r, c] = _dtResultClean.Rows[r][c].ToString();
                }
            }

            DrawTable(gfx, curX, curY + 5, _rowCount, _colCount, 15, _colWidth, _arrHeader, _arrData);

            curY += (15 + (_rowCount * 15)); //Talbe place holder
        }
        else
        {
            return "";
        }

       
        curY += 5;// 20; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks2_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks2_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks3_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks3_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks4_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks4_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        if (shPromotion)
        {
            // Promotion
            curY += 15;// 40; //New line
            if (lang == "th-TH")
            {
                gfx.DrawString("โปรโมชั่น สำหรับลุกค้าที่ตอบรับภายใน 7 วันนับจากที่ได้รับใบเสนอราคา", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("1. บริการรถยก (ค่าบริการ + 15 กิโลแรก)  ** สำหรับรถไม่เกิน 15 ปี ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("2. ค่าเสียเวลา 1,000 บาท     ** เคลมเป็นฝ่ายถูกเท่านั้น แจ้งเบิกภายใน 30 วันนับจากวันที่ได้รับใบเคลม , 1 ครั้ง / 1 ปีกรมธรรม์ ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("3. แจ้งต่อล่วงหน้า  15 วัน รับส่วนลดพิเศษเพิ่มเติม  200 - 1,000 บาท  ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("*** สำหรับเบี้ยประกันรถยนต์ ราคา 10,000 ขึ้นไป  ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
            }
            else
            {
                gfx.DrawString("Promotion for decision within 7 days after get quotation ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("1. Car lift (fee + 15 Km. first).   ** Car not over 15 years ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("2. Get 1000 Baht for waste time.   ** Right claim only and withdraw within 30 days from the date of receipt of claim/1 policy ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("3. Get discount more 200-1000 if buy insurance before 15 days notice. ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
                curY += 10; //New line
                gfx.DrawString("** Only for premiun more than 10,000 Baht ", fontFooter, XBrushes.Red, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
            }
        }

        curY += 15;// 40; //New line

        XPen _newpen = new XPen(_xcolor);

        if (_agentLicenseNo.Trim() != "")
        {
            //System.Drawing.Rectangle _newrect = new System.Drawing.Rectangle(curX, curY, 535, 30);
            XRect _newrect = new XRect(curX, curY, 535, 30);
            gfx.DrawRectangle(_newpen, _newrect);
            curY += 10;
            gfx.DrawString(Resources.General.Broker, font, XBrushes.Black, new XRect(curX + 5, curY, 15, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 38, curY, 38, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentName, font, XBrushes.Black, new XRect(curX + 43, curY, 43, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.LicenseNumber, font, XBrushes.Black, new XRect(curX + 140, curY, 20, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 195, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentLicenseNo, font, XBrushes.Black, new XRect(curX + 200, curY, 45, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.EmailAddress, font, XBrushes.Black, new XRect(curX + 255, curY, 20, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 275, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentEmail, font, XBrushes.Black, new XRect(curX + 280, curY, 45, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.ContactNo, font, XBrushes.Black, new XRect(curX + 410, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 450, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentContactNo, font, XBrushes.Black, new XRect(curX + 455, curY, 45, 15), XStringFormat.TopLeft);
        }
        else
        {
            //System.Drawing.Rectangle _newrect = new System.Drawing.Rectangle(curX, curY, 535, 30);
            XRect _newrect = new XRect(curX, curY, 535, 30);
            gfx.DrawRectangle(_newpen, _newrect);
            curY += 5;
            gfx.DrawString(Resources.General.Broker, font, XBrushes.Black, new XRect(curX + 20, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 80, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentName, font, XBrushes.Black, new XRect(curX + 85, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.EmailAddress, font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 240, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentEmail, font, XBrushes.Black, new XRect(curX + 245, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.ContactNo, font, XBrushes.Black, new XRect(curX + 400, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 440, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentContactNo, font, XBrushes.Black, new XRect(curX + 445, curY, 50, 15), XStringFormat.TopLeft);

            curY += 10;
            gfx.DrawString(Resources.CarInsurance.Supervisor, font, XBrushes.Black, new XRect(curX + 20, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 80, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentSupervisor, font, XBrushes.Black, new XRect(curX + 85, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.LicenseNumber, font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 240, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentSupLicenseNo, font, XBrushes.Black, new XRect(curX + 245, curY, 50, 15), XStringFormat.TopLeft);
        }

        curY += 15;// 40; //New line
        gfx.DrawString(_footer, fontFooter, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 10;

        string _filePath = GetFilePath();
        string filename = _filePath + "Quotes_" + _carid + "_" + dateTimeNow.ToString("_ddMMMyyyy_hhmmss_tt") + ".pdf"; //DateTime.Now.ToString("_ddMMMyyyy_hhmmss_tt")
        //document.Save(filename);
        // ...and start a viewer.
        //Response.Redirect(filename);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        document.Save(filename);
        stream.Close();
        document.Close();
        return filename;
    }

    public string GeneratePDFManualQuote()
    {
        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        // Set font encoding to unicode

        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

        document.Info.Title = "Created with PDFsharp";

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

       

        // Create a font
        XFont fontHeader = new XFont("Tahoma", 11, XFontStyle.Bold, options);
        XFont font = new XFont("Tahoma", 7.5d, XFontStyle.Regular, options);
        XFont fontFooter = new XFont("Tahoma", 7, XFontStyle.Bold, options);
        XFont fontAddress = new XFont("Tahoma", 10, XFontStyle.Regular, options);
        XColor _xcolor = new XColor();
        _xcolor.R = 0;
        _xcolor.G = 0;
        _xcolor.B = 0;
        System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(10, 10, 500, 100);
        XPen _pen = new XPen(_xcolor);
        int curX = 35;
        int curY = 30;

       
        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address1, fontHeader, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address2, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address3, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address4, fontAddress, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 12;

        gfx.DrawString(Resources.CarInsurance.PDFCompany_Address5, fontAddress, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 10;

        gfx.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + "/images/logos/gg_logo.png"), new XRect(curX + 380, 35, 73, 63));
        curY += 10;
        gfx.DrawString(Resources.CarInsurance.PDF_Title, fontHeader, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        //Sakthi on 14 Nov 2012 -- End

        curY += 15;// 20;

        gfx.DrawString(Resources.CarInsuranceResultPage.CustomerName, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_customername, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.DateNew, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(dateTimeNow.ToString("dd/MMM/yyyy"), font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);
       

        curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.ContactNo, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_mobile, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.LicensePlate, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carplatenumber, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.CarMakeModel, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carmakemodel, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        //curY += 10;
        gfx.DrawString(Resources.CarInsuranceResultPage.Year, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_carmodelyear, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsurance.VehicleType, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(VehicleTypeUsage, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        gfx.DrawString(Resources.CarInsurance.NamedDriver, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_nameddriver, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 10;
        gfx.DrawString(Resources.CarInsurance.NCB, font, XBrushes.Black, new XRect(curX, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 100, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_ncb, font, XBrushes.Black, new XRect(curX + 105, curY, 50, 15), XStringFormat.TopLeft);

        gfx.DrawString(Resources.CarInsuranceResultPage.PolicyStartDate, font, XBrushes.Black, new XRect(curX + 300, curY, 30, 15), XStringFormat.TopLeft);
        gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 400, curY, 50, 15), XStringFormat.TopLeft);
        gfx.DrawString(_commencementdate, font, XBrushes.Black, new XRect(curX + 405, curY, 50, 15), XStringFormat.TopLeft);

        curY += 20;
        gfx.DrawString(Resources.CarInsurance.PolicyDetail, fontAddress, XBrushes.Black, new XRect(curX, curY, 100, 15), XStringFormat.TopLeft);
        curY += 10;
        if (_dtresult != null && _dtresult.Rows.Count > 0)
        {
            DataTable _dtResultClean = new DataTable("tblResultClean");

            _dtResultClean.Columns.Add(Resources.General.InsuranceCompany);
            for (int i = 0; i < _dtresult.Rows.Count; i++)
            {
                //Company Name
                _dtResultClean.Columns.Add(_dtresult.Rows[i][6].ToString() + i.ToString());
            }

            DataRow _rowLogo = _dtResultClean.NewRow();
            _rowLogo[0] = Resources.General.InsuranceCompany;
            //_dtResultClean.Rows.Add(_rowLogo);

            DataRow _rowInsType = _dtResultClean.NewRow();
            _rowInsType[0] = Resources.CarInsurance.InsuranceType;

            DataRow _rowQuoteRefNo = _dtResultClean.NewRow();
            _rowQuoteRefNo[0] = Resources.CarInsurance.ReferenceNo;

          

            DataRow _rowGarageType = _dtResultClean.NewRow();
            _rowGarageType[0] = Resources.CarInsurance.GarageType;

            DataRow _rowDeductible = _dtResultClean.NewRow();
            _rowDeductible[0] = Resources.CarInsuranceResultPage.DECNormal;

            DataRow _rowFireTheft = _dtResultClean.NewRow();
            _rowFireTheft[0] = Resources.CarInsuranceResultPage.FireTheftNormal;

            DataRow _rowOwnDamage = _dtResultClean.NewRow();
            _rowOwnDamage[0] = Resources.CarInsuranceResultPage.OwnDamage;

            DataRow _rowTPPD = _dtResultClean.NewRow();
            _rowTPPD[0] = Resources.CarInsuranceResultPage.TPPDNormal;

            DataRow _rowTPBIA = _dtResultClean.NewRow();
            _rowTPBIA[0] = Resources.CarInsuranceResultPage.TPBIANormal;

            DataRow _rowTPBIP = _dtResultClean.NewRow();
            _rowTPBIP[0] = Resources.CarInsuranceResultPage.TPBIPNormal;

            DataRow _rowPA = _dtResultClean.NewRow();
            _rowPA[0] = Resources.CarInsuranceResultPage.PANormal;

            DataRow _rowMED = _dtResultClean.NewRow();
            _rowMED[0] = Resources.CarInsuranceResultPage.MEDNormal;

            DataRow _rowBB = _dtResultClean.NewRow();
            _rowBB[0] = Resources.CarInsuranceResultPage.BailBondNormal;

            DataRow _rowTotalVMI = _dtResultClean.NewRow();
            _rowTotalVMI[0] = Resources.CarInsurance.VMI;

            DataRow _rowCTPL = _dtResultClean.NewRow();
            _rowCTPL[0] = Resources.CarInsurance.CMI;
         
            DataRow _rowTotalPremium = _dtResultClean.NewRow();
            _rowTotalPremium[0] = "1). " + Resources.CarInsurance.FullPaymentwithTAX;
           
            DataRow _rowGGOffer = _dtResultClean.NewRow();
            _rowGGOffer[0] = Resources.General.AnnualPremium;

            DataRow _rowFloodCover = _dtResultClean.NewRow();
            _rowFloodCover[0] = Resources.CarInsuranceResultPage.FloodCover;

            DataRow _rowNameDriver = _dtResultClean.NewRow();
            _rowNameDriver[0] = Resources.NonGG.NamedDrivers;

            DataRow _rowPaymentOption = _dtResultClean.NewRow();
            _rowPaymentOption[0] = Resources.CarInsurance.PaymentOptions;
         
            DataRow _rowMonthlyInstallmentTitle = _dtResultClean.NewRow();
            _rowMonthlyInstallmentTitle[0] = Resources.CarInsurance.MonthlyInstallments;

            DataRow _rowInstallmentPerMonth = _dtResultClean.NewRow();
            _rowInstallmentPerMonth[0] = "2). " + Resources.CarInsurance.CashPayment; //Resources.CarInsurance.MonthlyInstallment;

            DataRow _rowNoOfInstallment = _dtResultClean.NewRow();
            _rowNoOfInstallment[0] = "3). " + Resources.CarInsurance.MonthlyInstallment; //Resources.CarInsurance.NoofInstallments;

            DataRow _rowCreditCardby = _dtResultClean.NewRow();
            _rowCreditCardby[0] = Resources.CarInsurance.CreditCardby;

            DataRow _rowZeroInterestFree = _dtResultClean.NewRow();
            _rowZeroInterestFree[0] = Resources.CarInsurance.ZeroPercentInterestFree;
         
            DataRow _rowThirdPartyCoverTitle = _dtResultClean.NewRow();
            _rowThirdPartyCoverTitle[0] = Resources.CarInsurance.ThirdPartyCover;

            DataRow _rowOwnerDamageCoverTitle = _dtResultClean.NewRow();
            _rowOwnerDamageCoverTitle[0] = Resources.CarInsurance.OwnerDamageCover;

            DataRow _rowAddCoverageperEndorseTitle = _dtResultClean.NewRow();
            _rowAddCoverageperEndorseTitle[0] = Resources.CarInsurance.AddCoverageperEndorsement;

            for (int r = 0; r < _dtresult.Rows.Count; r++)
            {
                string _logoUrl = _dtresult.Rows[r][7].ToString();

                _rowLogo[r + 1] = _logoUrl.Substring(1, _logoUrl.Length - 1); // LOGO
                if (_dtresult.Rows[r][16] != DBNull.Value && _dtresult.Rows[r][16].ToString() != string.Empty)
                {
                    _rowQuoteRefNo[r + 1] = _dtresult.Rows[r][16]; // Ref. No
                }
                else
                {
                    _rowQuoteRefNo[r + 1] = CE.Global.General.GetReferenceNumber(_dtresult.Rows[r][3].ToString(), _dtresult.Rows[r][1].ToString());
                }

                if (_dtresult.Rows[r][2] != DBNull.Value && _dtresult.Rows[r][2] != string.Empty)
                {
                    if (_dtresult.Rows[r][2].ToString() == "10")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class10; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "11")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class11; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "20")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class20; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "21")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class21; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "30")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class30; // Ins Type
                    }
                    else if (_dtresult.Rows[r][2].ToString() == "31")
                    {
                        _rowInsType[r + 1] = Resources.CarInsurance.PDFInsType_Class31; // Ins Type
                    }
                }

                
                if (_dtresult.Rows[r][14] != DBNull.Value && _dtresult.Rows[r][14] != string.Empty)
                {
                    if (_dtresult.Rows[r][14].ToString() == "1")
                    {
                        _rowGarageType[r + 1] = Resources.CarInsurance.Garage_Authorized; // Garage Type
                    }
                    else
                    {
                        _rowGarageType[r + 1] = Resources.CarInsurance.Garage_Dealer; // Garage Type
                    }
                }
               


                _rowGGOffer[r + 1] = Convert.ToSingle(_dtresult.Rows[r][17]).ToString("#,000.00"); // AnnualPremium
               
                _rowTotalVMI[r + 1] = Convert.ToSingle(_dtresult.Rows[r][20]).ToString("#,000.00"); //TotalVMI
                if (Convert.ToInt32(_dtresult.Rows[r][21]) > 0)
                {
                    if (Convert.ToInt32(_dtresult.Rows[r][21]) >= 1000)
                    {
                        _rowCTPL[r + 1] = Convert.ToSingle(_dtresult.Rows[r][21]).ToString("#,000.00"); //TotalCMI
                    }
                    else
                    {
                        _rowCTPL[r + 1] = Convert.ToSingle(_dtresult.Rows[r][21]).ToString("#.00"); //TotalCMI
                    }
                }
                else
                {
                    _rowCTPL[r + 1] = "N/A";
                } /**/
              
                _rowTotalPremium[r + 1] = (Convert.ToSingle(_dtresult.Rows[r][21].ToString()) + Convert.ToSingle(_dtresult.Rows[r][20].ToString())).ToString("#,000.00");

               
                _rowThirdPartyCoverTitle[r + 1] = " ";
                _rowOwnerDamageCoverTitle[r + 1] = " ";
                _rowAddCoverageperEndorseTitle[r + 1] = " ";
              

                Int64 _strBrokerProvider = 0;
                string _strPaymentOption = "FP";
                string _strTotalInstallment = "0.00";
                string _strFirstInstallment = "0.00";
                string _strLastInstallment = "0.00";
                Int32 _Days = 0;
                Int32 _Installments = 3;
                Int32 _Install = _Installments - 1;
                string _strFirstInstallmentDesc = "";
                string _strLastInstallmentDesc = "";
                string _InerestFree = "√";
                string _BankCode = "BKK";

                if (_dtresult.Rows[r]["CXBrokerProviderId"] != DBNull.Value && _dtresult.Rows[r]["CXBrokerProviderId"].ToString() != string.Empty)
                {
                    _strBrokerProvider = Convert.ToInt32(_dtresult.Rows[r]["CXBrokerProviderId"].ToString());
                }

                if (_dtresult.Rows[r]["DiffDate"] != DBNull.Value && _dtresult.Rows[r]["DiffDate"].ToString() != string.Empty)
                {
                    _Days = Convert.ToInt32(_dtresult.Rows[r]["DiffDate"].ToString());
                }

                if (_dtresult.Rows[r]["PaymentOption"] != DBNull.Value && _dtresult.Rows[r]["PaymentOption"].ToString() != string.Empty)
                {
                    _strPaymentOption = _dtresult.Rows[r]["PaymentOption"].ToString();
                }

                if (_dtresult.Rows[r]["NoofInstallMent"] != DBNull.Value && _dtresult.Rows[r]["NoofInstallMent"].ToString() != string.Empty)
                {
                    _Installments = Convert.ToInt32(_dtresult.Rows[r]["NoofInstallMent"].ToString());
                }

                if (_dtresult.Rows[r]["Bank"] != DBNull.Value && _dtresult.Rows[r]["Bank"].ToString() != string.Empty)
                {
                    _BankCode = _dtresult.Rows[r]["Bank"].ToString();
                }
                _strFirstInstallmentDesc = "(1 " + Resources.CarInsurance.To + " " + _Install.ToString() + " " + Resources.CarInsurance.Months + ")";
                _strLastInstallmentDesc = Resources.CarInsurance.LastMonthInstallment;

                if (_strBrokerProvider == 29)
                {
                    if (_BankCode == "KBANK")
                    {
                        _InerestFree = "√";
                    }
                    else
                    {
                        _InerestFree = "X";
                    }
                    _strFirstInstallment = (Convert.ToSingle(_dtresult.Rows[r]["InstallmentAmountWD"].ToString())).ToString("#,000.00");
                    _strLastInstallment = (Convert.ToSingle(_dtresult.Rows[r]["LastInstallmentAmountWD"].ToString())).ToString("#,000.00");
                    _strTotalInstallment = (Convert.ToSingle(_dtresult.Rows[r]["IPFinalAnnualPremiumWD"].ToString())).ToString("#,000.00");
                    

                }
                else
                {
                    _strFirstInstallment = (Convert.ToSingle(_dtresult.Rows[r]["InstallmentAmountWOD"].ToString())).ToString("#,000.00");
                    _strLastInstallment = (Convert.ToSingle(_dtresult.Rows[r]["LastInstallmentAmountWOD"].ToString())).ToString("#,000.00");
                    _strTotalInstallment = (Convert.ToSingle(_dtresult.Rows[r]["IPFinalAnnualPremiumWOD"].ToString())).ToString("#,000.00");
                }

                

                _rowPaymentOption[r + 1] = " ";
                _rowMonthlyInstallmentTitle[r + 1] = " ";
                if (_strPaymentOption == "IP")
                {
                    _rowInstallmentPerMonth[r + 1] = Convert.ToSingle(_strTotalInstallment).ToString("#,000.00");
                    Single installmentAmt = (Convert.ToSingle(_strTotalInstallment) / _Installments);
                    if (installmentAmt > 1000)
                        _rowNoOfInstallment[r + 1] = Convert.ToSingle(_strTotalInstallment).ToString("#,000.00") + " (" +
                            _Installments.ToString() + " x " + installmentAmt.ToString("#,000.00") + ")";
                    else
                        _rowNoOfInstallment[r + 1] = "";

                    //Yui@15072014
                    if (_BankCode == "KBANK")
                    {
                        _rowCreditCardby[r + 1] = Resources.CarInsurance.KBANKCreditCard; //GetBankName(_BankCode); 
                    }
                    else
                    {
                        _rowCreditCardby[r + 1] = GetBankName(_BankCode);
                    }

                    _rowZeroInterestFree[r + 1] = _InerestFree;
                }
                else
                {
                    _Installments = 3;
                    _strFirstInstallment = (Convert.ToSingle(_dtresult.Rows[r]["InstallmentAmountWOD"].ToString())).ToString("#,000.00");
                    _strLastInstallment = (Convert.ToSingle(_dtresult.Rows[r]["LastInstallmentAmountWOD"].ToString())).ToString("#,000.00");
                    _strTotalInstallment = (Convert.ToSingle(_dtresult.Rows[r]["IPFinalAnnualPremiumWOD"].ToString())).ToString("#,000.00");

                    _rowInstallmentPerMonth[r + 1] = Convert.ToSingle(_strTotalInstallment).ToString("#,000.00");

                    Single installmentAmt = (Convert.ToSingle(_strTotalInstallment) / _Installments);
                    if (installmentAmt > 1000)
                        _rowNoOfInstallment[r + 1] = Convert.ToSingle(_strTotalInstallment).ToString("#,000.00") + " (" +
                            _Installments.ToString() + " x " + installmentAmt.ToString("#,000.00") + ")";
                    else
                        _rowNoOfInstallment[r + 1] = "";

                    _rowCreditCardby[r + 1] = Resources.CarInsurance.KBANKCreditCard; //GetBankName("KBANK");
                    _rowZeroInterestFree[r + 1] = "√";
                }

                if (_strPaymentOption == "FP")
                {
                    //_rowTotalPremium[r + 1] = Convert.ToSingle(_dtresult.Rows[r][9]).ToString("#,000.00"); //FinalAnnualPremium
                    _rowInstallmentPerMonth[r + 1] = Convert.ToSingle(_dtresult.Rows[r][9]).ToString("#,000.00");
                }
               

                _rowTPPD[r + 1] = _dtresult.Rows[r][23]; //TPPD
                _rowTPBIP[r + 1] = _dtresult.Rows[r][24]; //TPBIP
                _rowTPBIA[r + 1] = _dtresult.Rows[r][25]; //TPBIA
                _rowDeductible[r + 1] = _dtresult.Rows[r][26]; //DEC
                _rowFireTheft[r + 1] = _dtresult.Rows[r][28]; //FireTheft
                _rowOwnDamage[r + 1] = _dtresult.Rows[r][29]; //OwnDamage
                _rowPA[r + 1] = _dtresult.Rows[r][30]; //PADriver
                _rowMED[r + 1] = _dtresult.Rows[r][32]; //MedicalExpense
                _rowBB[r + 1] = _dtresult.Rows[r][33]; //BailBond

                if (_dtresult.Rows[r][37] != DBNull.Value)
                {
                    _rowFloodCover[r + 1] = _dtresult.Rows[r][37]; //Flood Cover (Info5)
                }

                if (_dtresult.Rows[r][38] != DBNull.Value) //Named Driver (Info6)
                {
                    if (_dtresult.Rows[r][38].ToString() == "1")
                    {
                        _rowNameDriver[r + 1] = "Yes";
                    }
                    else
                    {
                        _rowNameDriver[r + 1] = "No";
                    }
                }
            }

            _dtResultClean.Rows.Add(_rowLogo);
            _dtResultClean.Rows.Add(_rowInsType);
            _dtResultClean.Rows.Add(_rowQuoteRefNo);
          
            _dtResultClean.Rows.Add(_rowGarageType);
            _dtResultClean.Rows.Add(_rowNameDriver);

            _dtResultClean.Rows.Add(_rowThirdPartyCoverTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowTPBIP);     //Bodily Injury/Death (per person) 
            _dtResultClean.Rows.Add(_rowTPBIA);     //Liability for Bodily Injury/Death 
            _dtResultClean.Rows.Add(_rowTPPD);      //Liability for Property Damage
            _dtResultClean.Rows.Add(_rowDeductible);

            _dtResultClean.Rows.Add(_rowOwnerDamageCoverTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowOwnDamage);
            _dtResultClean.Rows.Add(_rowFireTheft);
            _dtResultClean.Rows.Add(_rowFloodCover);

            _dtResultClean.Rows.Add(_rowAddCoverageperEndorseTitle);   //Sakthi add on 12 Dec 2012
            _dtResultClean.Rows.Add(_rowPA);        //Personal Accident (per person)
            _dtResultClean.Rows.Add(_rowMED);       //Medical Expenses (per person)
            _dtResultClean.Rows.Add(_rowBB);        //Bail Bond (per accident)

            //Sakthi Hide on 23 Nov 2012 -- Start
            _dtResultClean.Rows.Add(_rowCTPL);
            _dtResultClean.Rows.Add(_rowTotalVMI);
            //Sakthi Hide on 23 Nov 2012 -- End
            _dtResultClean.Rows.Add(_rowPaymentOption);
            _dtResultClean.Rows.Add(_rowTotalPremium);


          
            _dtResultClean.Rows.Add(_rowInstallmentPerMonth);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowNoOfInstallment);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowCreditCardby);//Sakthi add on 03 Dec 2012
            _dtResultClean.Rows.Add(_rowZeroInterestFree);//Sakthi add on 03 Dec 2012


           
            int _colCount = _dtResultClean.Columns.Count;
            int _rowCount = _dtResultClean.Rows.Count;

            string[] _arrHeader = new string[_colCount];
            int[] _colWidth = new int[_colCount];
            for (int i = 0; i < _colCount; i++)
            {
                _arrHeader[i] = _dtResultClean.Columns[i].ColumnName;
                if (i == 0)
                {
                    _colWidth[i] = 150;
                }
                else
                {
                    _colWidth[i] = 90;
                }
            }

            string[,] _arrData = new string[_rowCount, _colCount];
            for (int r = 0; r < _rowCount; r++)
            {
                for (int c = 0; c < _colCount; c++)
                {
                    _arrData[r, c] = _dtResultClean.Rows[r][c].ToString();
                }
            }

            DrawTable(gfx, curX, curY + 5, _rowCount, _colCount, 16, _colWidth, _arrHeader, _arrData);

            curY += (16 + (_rowCount * 16)); //Talbe place holder
        }
        else
        {
            return "";
        }

        
        curY += 10;// 20; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks2_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks2_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks3_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks3_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString(Resources.CarInsurance.PDFFooter_Remarks4_1, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);

        curY += 10; //New line
        gfx.DrawString("     " + Resources.CarInsurance.PDFFooter_Remarks4_2, fontFooter, XBrushes.Black, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
      

        curY += 25;// 40; //New line

        XPen _newpen = new XPen(_xcolor);

        if (_agentLicenseNo.Trim() != "")
        {
            //System.Drawing.Rectangle _newrect = new System.Drawing.Rectangle(curX, curY, 535, 30);
            XRect _newrect = new XRect(curX, curY, 535, 30);
            gfx.DrawRectangle(_newpen, _newrect);
            curY += 10;
            gfx.DrawString(Resources.General.Broker, font, XBrushes.Black, new XRect(curX + 5, curY, 15, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 38, curY, 38, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentName, font, XBrushes.Black, new XRect(curX + 43, curY, 43, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.LicenseNumber, font, XBrushes.Black, new XRect(curX + 140, curY, 20, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 195, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentLicenseNo, font, XBrushes.Black, new XRect(curX + 200, curY, 45, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.EmailAddress, font, XBrushes.Black, new XRect(curX + 255, curY, 20, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 275, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentEmail, font, XBrushes.Black, new XRect(curX + 280, curY, 45, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.ContactNo, font, XBrushes.Black, new XRect(curX + 410, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 450, curY, 40, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentContactNo, font, XBrushes.Black, new XRect(curX + 455, curY, 45, 15), XStringFormat.TopLeft);
        }
        else
        {
            //System.Drawing.Rectangle _newrect = new System.Drawing.Rectangle(curX, curY, 535, 30);
            XRect _newrect = new XRect(curX, curY, 535, 30);
            gfx.DrawRectangle(_newpen, _newrect);
            curY += 5;
            gfx.DrawString(Resources.General.Broker, font, XBrushes.Black, new XRect(curX + 20, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 80, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentName, font, XBrushes.Black, new XRect(curX + 85, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.EmailAddress, font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 240, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentEmail, font, XBrushes.Black, new XRect(curX + 245, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.ContactNo, font, XBrushes.Black, new XRect(curX + 400, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 440, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentContactNo, font, XBrushes.Black, new XRect(curX + 445, curY, 50, 15), XStringFormat.TopLeft);

            curY += 10;
            gfx.DrawString(Resources.CarInsurance.Supervisor, font, XBrushes.Black, new XRect(curX + 20, curY, 30, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 80, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentSupervisor, font, XBrushes.Black, new XRect(curX + 85, curY, 50, 15), XStringFormat.TopLeft);

            gfx.DrawString(Resources.CarInsurance.LicenseNumber, font, XBrushes.Black, new XRect(curX + 180, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(":", font, XBrushes.Black, new XRect(curX + 240, curY, 50, 15), XStringFormat.TopLeft);
            gfx.DrawString(_agentSupLicenseNo, font, XBrushes.Black, new XRect(curX + 245, curY, 50, 15), XStringFormat.TopLeft);
        }
        curY += 15;// 40; //New line
        gfx.DrawString(_footer, fontFooter, XBrushes.Blue, new XRect(curX, curY, 50, 20), XStringFormat.TopLeft);
        curY += 10;

        





        string _filePath = GetFilePath();
        string filename = _filePath + "Quotes_" + _carid + "_" + dateTimeNow.ToString("_ddMMMyyyy_hhmmss_tt") + ".pdf"; //DateTime.Now.ToString("_ddMMMyyyy_hhmmss_tt")
        //document.Save(filename);
        // ...and start a viewer.
        //Response.Redirect(filename);
        System.IO.MemoryStream stream = new System.IO.MemoryStream();
        document.Save(filename);
        stream.Close();
        document.Close();
        return filename;
    }

    private string GetFilePath()
    {
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NonGGFileOutputPath").ToString();
        _filePath += "pdfoutput\\carinsurance\\";
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();

        string _curYear = dateTimeNow.ToString("yyyy"); //DateTime.Now.ToString("yyyy");
        if (!_myIO.CheckDirectory(_filePath + _curYear))
        {
            if (_myIO.CreateDirectory(_filePath, _curYear))
            {
                _filePath += _curYear + "\\";
            }
        }
        else
        {
            _filePath += _curYear + "\\";
        }

        string _curMonth = dateTimeNow.ToString("MMMM"); //DateTime.Now.ToString("MMMM");
        if (!_myIO.CheckDirectory(_filePath + _curMonth))
        {
            if (_myIO.CreateDirectory(_filePath, _curMonth))
            {
                _filePath += _curMonth + "\\";
            }
        }
        else
        {
            _filePath += _curMonth + "\\";
        }

        string _todaydate = dateTimeNow.ToString("ddMMMMyyyy"); //DateTime.Now.ToString("ddMMMMyyyy");
        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        string _quotes = "Quotes_" + _todaydate;
        if (!_myIO.CheckDirectory(_filePath + _quotes))
        {
            if (_myIO.CreateDirectory(_filePath, _quotes))
            {
                _filePath += _quotes + "\\";
            }
        }
        else
        {
            _filePath += _quotes + "\\";
        }

        return _filePath;
    }

    private void DrawTable(XGraphics _objG, int x, int y, int rows, int cols, int rowHeight, int[] _arrColsWidth, string[] _arrHeader, string[,] _arrData)
    {
        XColor _xcolor = new XColor();
        _xcolor.R = 0;
        _xcolor.G = 0;
        _xcolor.B = 0;

        //System.Drawing.Rectangle _rect = new System.Drawing.Rectangle(0, 0, 0, 0);
        //System.Drawing.Rectangle _rectBig = new System.Drawing.Rectangle(0, 0, 0, 0);
        //System.Drawing.Rectangle _rectLogo = new System.Drawing.Rectangle(0, 0, 0, 0);
        XRect _rect = new XRect(0, 0, 0, 0);
        XRect _rectBig = new XRect(0, 0, 0, 0);
        XRect _rectLogo = new XRect(0, 0, 0, 0);

        _rect.X = x;
        _rect.Y = y;
        _rectBig.X = x;
        _rectBig.Y = y;
        _rectLogo.X = x;
        _rectLogo.Y = y;
        _rect.Width = _arrColsWidth[0];
        _rect.Height = rowHeight;
        _rectBig.Width = _arrColsWidth[0];
        _rectBig.Height = rowHeight + 40;
        _rectLogo.Width = _arrColsWidth[0];
        _rectLogo.Height = rowHeight + 10;

        XPen _pen = new XPen(_xcolor);
        _pen.Width = 0.5d;
        XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
        XFont font = new XFont("Tahoma", 7, XFontStyle.Regular, options);
        XFont headerFont = new XFont("Tahoma", 10, XFontStyle.Bold, options);
        XFont fontBigger = new XFont("Tahoma", 9, XFontStyle.Bold, options);
        XFont fontBiggerUL = new XFont("Tahoma", 9, XFontStyle.Bold | XFontStyle.Underline, options);
        XFont fontbold = new XFont("Tahoma", 7, XFontStyle.Bold, options);
        

        for (int i = 0; i < rows; i++)
        {
            // Draw the text
            for (int j = 0; j < cols; j++)
            {
                _rect.Width = _arrColsWidth[j];
                _rectBig.Width = _arrColsWidth[j];
                _rectLogo.Width = _arrColsWidth[j];
                if (j > 0 && i == 0)
                {
                    _objG.DrawRectangle(_pen, _rectLogo);
                    _objG.DrawImage(XImage.FromFile(AppDomain.CurrentDomain.BaseDirectory + _arrData[i, j].ToString()), new XRect(_rectLogo.X + 5, _rectLogo.Y + 5, 50, 20));
                }
                else
                {
                    if (j == 0 && i == 0)
                    {
                        _objG.DrawRectangle(_pen, _rectLogo);
                    }
                             
                    else if (i == rows - 5)
                    {
                        _objG.DrawRectangle(new XSolidBrush(XBrushes.LightBlue), _rect);
                        _objG.DrawRectangle(_pen, _rect);
                    }
                    else if (i == rows - 4)
                    {
                        _objG.DrawRectangle(new XSolidBrush(XBrushes.Yellow), _rect);
                        _objG.DrawRectangle(_pen, _rect);
                    }
                    else if (i == rows - 3)
                    {
                        _objG.DrawRectangle(new XSolidBrush(XBrushes.LightBlue), _rect);
                        _objG.DrawRectangle(_pen, _rect);
                    }
                    else if (i == rows - 2)
                    {
                        _objG.DrawRectangle(new XSolidBrush(XBrushes.LightBlue), _rect);
                        _objG.DrawRectangle(_pen, _rect);
                    }
                    else if (i == rows - 1)
                    {
                        _objG.DrawRectangle(new XSolidBrush(XBrushes.LightBlue), _rect);
                        _objG.DrawRectangle(_pen, _rect);
                    }
                    else
                    {
                        _objG.DrawRectangle(_pen, _rect);
                    }

                    if (j > 0 && i == rows - 1) // 0% Insterest Free 
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);

                    }
                    else if (j > 0 && i == rows - 2) // Credit Card
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);

                    }
                    else if (j > 0 && i == rows - 3) // No of Installment 
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);

                    }
                    else if (j > 0 && i == rows - 4) // Installment per Monmth
                    {
                        //_objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        _objG.DrawString(_arrData[i, j].ToString(), fontBigger, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);

                    }
                    //else if (j > 0 && i == rows - 5) // Monthly Installment Title
                    //{
                    //    _objG.DrawString(_arrData[i, j].ToString(), fontBigger, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);

                    //}
                    else if (j > 0 && i == rows - 5) // GG OFFER PREMIUM
                    {
                        _objG.DrawString(_arrData[i, j].ToString(), fontBigger, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                    }
                    else
                    {
                        if (j == 0 && i == 0) //Insurance Company Name
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 9, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 21)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontbold, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 16)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontbold, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 12)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontbold, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 6)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontBiggerUL, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 5)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontbold, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        //else if (j == 0 && i == rows - 5)
                        //{
                        //    _objG.DrawString(_arrData[i, j].ToString(), fontBiggerUL, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        //}
                        else if (j == 0 && i == rows - 4)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), fontbold, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 3)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 2)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else if (j == 0 && i == rows - 1)
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                        else
                        {
                            _objG.DrawString(_arrData[i, j].ToString(), font, XBrushes.Black, new XRect(_rect.X + 10, _rect.Y + 3, 10, 10), XStringFormats.TopLeft);
                        }
                    }
                }

                _rect.X += _arrColsWidth[j];
                _rectBig.X += _arrColsWidth[j];
                _rectLogo.X += _arrColsWidth[j];
            }

            if (i == 0)
            {
                _rect.Y += rowHeight + 10;
            }
            else
            {
                _rect.Y += rowHeight;
            }
            _rect.X = x;
        }
    }

    private string GetMonthlyInstallmentTitle()
    {
        string _Title = "";
        _Title = Resources.CarInsurance.MonthsInstallments;
        _Title += "@" + Resources.CarInsurance.InstallmentperMonth;
        _Title += "@" + Resources.CarInsurance.NoofInstallments;
        _Title += "@" + Resources.CarInsurance.CreditCardby;
        _Title += "@" + Resources.CarInsurance.ZeroPercentInterestFree;
        return _Title;
    }

    private string GetBankName(string BankCode)
    {
        string _BankName = "";
        if (BankCode == "BKK")
        {
            _BankName = Resources.CarInsurance.BankBKK;
        }
        else if (BankCode == "KBANK")
        {
            _BankName = Resources.CarInsurance.BankK;
        }
        else if (BankCode == "KTC")
        {
            _BankName = Resources.CarInsurance.BankKTC;
        }
        else if (BankCode == "CITI")
        {
            _BankName = Resources.CarInsurance.BankCITI;
        }
        else if (BankCode == "AYA")
        {
            _BankName = Resources.CarInsurance.BankAYA;
        }
        else if (BankCode == "CTRL")
        {
            _BankName = Resources.CarInsurance.CentralCard;
        }
        else if (BankCode == "RBSN")
        {
            _BankName = Resources.CarInsurance.RobinsonCard;
        }
        else if (BankCode == "HPRO")
        {
            _BankName = Resources.CarInsurance.HomeproCard;
        }
        return _BankName;
    }

}
